//
//  HNProductListConsumeSureView.m
//  ZYManagementSystem
//
//  Created by 星道 on 17/6/14.
//  Copyright © 2017年 焕宁. All rights reserved.
//

#import "HNProductListConsumeSureView.h"

@implementation HNProductListConsumeSureView
{
    IBOutlet UIView *_BackView;
    IBOutlet UITextField *_TextField;
    void (^_ClickCommit)(NSString *);
    IBOutlet UIImageView *_CloseImg;
}


+ (instancetype)ConsumeSure_ClickCommit:(void (^)(NSString *))ClickCommit
{
    return [[self alloc] initWithClickCommit:ClickCommit];
}




//初始化
- (instancetype)initWithClickCommit:(void (^)(NSString *))ClickCommit
{
    self = [[[NSBundle mainBundle] loadNibNamed:[HNProductListConsumeSureView description] owner:nil options:nil] lastObject];
    if (self) {

        [[UIApplication sharedApplication].keyWindow addSubview:self];

        self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREENH_HEIGHT);

        _ClickCommit = ClickCommit;

        //textfield加上阴影效果
        [[_BackView layer] setMasksToBounds:YES];
        [[_BackView layer] setShadowOffset:CGSizeMake(1, 1)]; // 阴影的范围
        [[_BackView layer] setShadowRadius:3];                // 阴影扩散的范围控制
        [[_BackView layer] setShadowOpacity:1];               // 阴影透明度
        [[_BackView layer] setShadowColor:[UIColor blackColor].CGColor]; // 阴影的颜色
        [_BackView setClipsToBounds:NO];


        //添加关闭手势
        [_CloseImg addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Close)]];

        self.alpha = 0;

        [self Show];
    }
    return self;
}



/**
 提交消费
 */
- (IBAction)CommitConsume:(UIButton *)sender {

    _ClickCommit (_TextField.text);
}





/**
 显示自己
 */
- (void)Show {
    //动画展示
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 1;
    }];
}



/**
 移除自己，并关闭界面
 */
- (void)Close {

    [self endEditing:YES];

    //动画开始
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];

}
@end
